<?php
abstract class DI_Abstract
{
	private static $_stores = array();
	
	private function _getClass()
	{
		return get_class($this);
	}
	
	public function __construct()
	{
		$class = $this->_getClass();
		
		if(! isset(self::$_stores[$class]))
		{
			self::$_stores[$class] = array();
			
			$metadatas = DI_Metadata::metadata($this);
			
			foreach ($metadatas as $propertyName => $value)
			{
				$inject = new DI_Inject();
				
				$inject->value = $value;
				
				self::$_stores[$class][$propertyName] = $inject;
				
				unset($this->{$propertyName});
			}
		}
		
		$this->container();
	}
	
	public function __set($name, $value)
	{
		$class = $this->_getClass();
		
		if(isset(self::$_stores[$class][$name]))
		{
			self::$_stores[$class][$name]->value = $value;
		}
	}
	
	public function __get($name)
	{
		$result = null;
		
		$class = $this->_getClass();
		
		if(isset(self::$_stores[$class][$name]))
		{
			$result = self::$_stores[$class][$name]->instance();
		}
		
		return $result;
	}
	
	abstract public function container();
}